<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div style="margin-bottom: 5px;">

    <!-- 示例-970 -->


</div>

<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
    <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
    <button class="layui-btn" data-type="isAll">验证是否全选</button>
<!--    <button class="layui-btn" layui-event="save"><a href="addNewCar.html">新增</a> </button>-->
    <button class="layui-btn"  layui-event="save"> <a class="layui-btn layui-btn-sm" id="add-user-btn" href="addNewCar.html">添加用户</a></button>
</div>

<!--<div id="add-user-layer" style="display: none; padding: 20px">-->
<!--    <form id="add-user-form" class="layui-form layui-form-pane">-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">姓名</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="text" name="name" class="layui-input" lay-verify="required" autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">密码</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="password" name="pass" class="layui-input" lay-verify="required">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">生日</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="date" name="birthday" class="layui-input" lay-verify="required" autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->


<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">年龄</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="text" name="age" class="layui-input" lay-verify="required" autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <div class="layui-input-block">-->
<!--                <button class="layui-btn" lay-submit lay-filter="add-user-form-submit">提交</button>-->
<!--                <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
<!--            </div>-->
<!--        </div>-->
<!--    </form>-->
<!--</div>-->

<table class="layui-table" lay-data="{width: 1200, height:768, url: '/admin/getallcar', page:true, id:'idTest'}" lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field:'c_id', width:100, sort: true,fixed: true}">ID</th>
        <th lay-data="{field:'car_name', width:150}">名称</th>
        <th lay-data="{field:'car_type', width:150 }">类型</th>
        <th lay-data="{field:'car_sitname', width:100}">座位数</th>
        <th lay-data="{field:'c_price', width:100}">日租价格</th>
        <th lay-data="{field:'c_number', width:100}">余量</th>
        <th lay-data="{field:'car_picture', width:250}">图片</th>

        <th lay-data="{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}"></th>
    </tr>
    </thead>
</table>

<script type="text/html" id="barDemo">
    <!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        var form=layui.form;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            var $=layui.$;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    // window.localStorage.setItem("uid",data.uid);
                    var id=data.c_id;
                    console.log(id);
                    $.ajax({
                        url:'/admin/deleteByCid/'+id,
                        type:'delete',
                        contentType:"application/json",
                    })
                    console.log(data.uid);
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                // layer.alert('编辑行：<br>'+ JSON.stringify(data));
                window.localStorage.setItem("c_id",data.c_id);

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/updateCarIno.html',
                });

            }else if(obj.event==='save'){
                console.log(111);
            }

        });

        // var $ = layui.$, active = {
        //     getCheckData: function(){ //获取选中数据
        //         var checkStatus = table.checkStatus('idTest')
        //             ,data = checkStatus.data;
        //         layer.alert(JSON.stringify(data));
        //     }
        //     ,getCheckLength: function(){ //获取选中数目
        //         var checkStatus = table.checkStatus('idTest')
        //             ,data = checkStatus.data;
        //         layer.msg('选中了：'+ data.length + ' 个');
        //     }
        //     ,isAll: function(){ //验证是否全选
        //         var checkStatus = table.checkStatus('idTest');
        //         layer.msg(checkStatus.isAll ? '全选': '未全选')
        //     }
        // };
        //
        // $('.demoTable .layui-btn').on('click', function(){
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        // });

    });


</script>

</body>
</html>